package 动态规划;

public class 斐波那契数列 {

    //迭代方式
    public int Fibonacci(int number){
        if (number <= 0 ){
            return  0;
        }
        if (number == 1 || number == 2){
            return 1;
        }
        int first = 1,second = 1,third = 0;
        for (int i = 3; i <= number; i++) {
            third = first +second;
            first = second;
            second = third;
        }
        return third;

    }

    //递归方式
    public int Fibonacci2(int number){
        if (number <= 0 ){
            return  0;
        }
        if (number == 1 || number == 2){
            return 1;
        }
        return Fibonacci2(number - 2)+Fibonacci2(number - 1);
    }


}
